﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApp.BaseDataSvc;
using YY.Common;

namespace WebApp
{
    public partial class ResetPwdFrm : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ResetPwdFrm), this);
        }

        [AjaxPro.AjaxMethod]
        public AjaxResult<bool> ResetPwd(string eOPwd,string ePwd)
        {
            AjaxResult<bool> result = new AjaxResult<bool>();
            result.Data = false;
            result.Msg = null;
            try
            {
                TB_User user = Session["User"] as TB_User;
                if (user != null)
                {
                    string oPwd = string.IsNullOrEmpty(eOPwd) ? null : EncryptCommon.MD5Encrypt(eOPwd);
                    if (oPwd != user.pwd)
                    {
                        result.Msg = "原密码输入不正确！";
                        return result;
                    }

                    string nPwd = string.IsNullOrEmpty(ePwd) ? null : EncryptCommon.MD5Encrypt(ePwd);
                    user.pwd = nPwd;

                    result.Data = this.BaseDataProxy.UpdateUser(user);
                }
                else
                    result.Msg = "请先登录！";
            }
            catch (Exception ex)
            {
                result.Data = false;
                result.Msg = ex.Message;
            }
            return result;
        }
    }
}
